<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/15
 * Time: 9:37
 */

namespace app\admin\controller;

use app\admin\model\AdminNavGroup as AdminNavGroupModel;
use think\Request;

class AdminnavgroupController extends BaseController
{
    public function lst()
    {
        $data = AdminNavGroupModel::order('id','asc')->paginate(8);
        $page = $data->render();
        $this->assign([
            'page' => $page,
            'data' => $data,
        ]);
        return $this->fetch();
    }

    public function add()
    {
        $request = Request::instance();
        switch  ($request->method()){
            case "GET":
                return $this->fetch();
                break;
            case "POST":
                $params = $request->param();
                $model = new AdminNavGroupModel();
                if($model->allowField(true)->save($params)){
                    $this->success('添加分组信息成功!',url('admin/adminnavgroup/lst'),'',1);
                    exit;
                }
                else{
                    $this->error($model->getError());
                    exit;
                }
                break;
            default:
                return "错误的数据信息";
        }
    }

    public function edi()
    {
        $request = Request::instance();
        switch  ($request->method()){
            case "GET":
                $id = $request->param('id');
                $this->assign('data',AdminNavGroupModel::find($id));
                return $this->fetch();
                break;
            case "POST":
                $params = $request->param();
                $model = new AdminNavGroupModel();
                if($model->allowField(true)->isUpdate(true)->save($params)){
                    $this->success('修改节点成功!',url('admin/adminnavgroup/lst'),'',1);
                    exit;
                }
                else{
                    $this->error($model->getError());
                    exit;
                }
                break;
            default:
                return "错误的数据信息";
        }
    }

    public function del()
    {
        $id = $this->request->param("id");
        if(AdminNavGroupModel::destroy($id)){
            return true;
        }
        return false;
    }
}